#!/usr/bin/python
# -*- encoding: utf-8 -*-
'''
@File    :   1.py
@Time    :   2020/05/26 14:09:14
@Author  :   Malygos_l 
@Version :   1.0
@Contact :   751756061@qq.com
@WebSite :   www.gitee.com/malygos_l
'''
# Start typing your code from here
# 定义一个狗类,里面有一个 列表成员变量(列表的元素是字典), 分别记录了 3种颜色的狗的颜色, 数量,和价格;
# 实现狗的买卖交易方法;  打印输出经过2-3次买卖方法后,剩下的各类狗的数量;


class dogs:
    #list
    Attribute = [{'color':'black','num':4,'price':30},
                 {'color':'brown','num':6,'price':40},
                 {'color':'white','num':5,'price':60}]
    
    #交易方法
    def deal(self,color,num):
        for dog in dogs.Attribute:
            if dog['color'] == color:
                if dog['num'] != 0:
                    print("你买了%d只狗" % num)
                    dog['num'] -= num
                    return
                else:
                    print("该颜色的狗已经卖完了")
                    return
            
        print("没有这种颜色的狗")

    # 打印剩下狗的数量
    def print_attribute(self):
        print("\n剩下的各类狗的数量：")
        for dog in dogs.Attribute:
            print("颜色:%s\t数量:%d" % (dog['color'],dog['num']))


def main():
    dog_test = dogs()
    dog_test.deal('blue',1)  #无此颜色的狗
    dog_test.deal('white',2)
    dog_test.deal('brown',3)

    dog_test.print_attribute()


if __name__ == "__main__":
    main()            